function imode=bcoe_eyelink1k_setup(w)
% create file elsewhere

if eyelink('initialize') ~= 0
    button = questdlg_offscreen('eyelink is not connecting','no EL1K','exit','DUMMY mode','DUMMY mode');
    if button(1)=='D'
        eyelink('initializedummy');
        imode=0;
    else
        disp('program exited by user')
        imode=-1;
        return
    end
end
imode=1;
clc;

% if nargin==0
% disp('???')
% file_name=input('Input file name (<=8 chars, no .edf needed):','s');
% end
%i = EYELINK('openfile',[file_name,'.edf']);
% if i~=0 & imode~='D'
%     EYELINK('Shutdown');
%     disp(' ');
%     error(['Cannot create EDF file: ' file_name]);
%     imode=-1;
%     return;
% end
EYELINK('command', 'add_file_preamble_text', 'Recorded by BCOE');
%   SET UP TRACKER CONFIGURATION
eyelink('command', 'calibration_type = HV9');
%	set parser (conservative saccade thresholds)
eyelink('command', 'saccade_velocity_threshold = 35');
eyelink('command', 'saccade_acceleration_threshold = 9500');
%	set EDF file contents
% eyelink('command', 'file_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE');
eyelink('command', 'file_event_filter = LEFT,RIGHT,MESSAGE');
% Sets which types of events will be written to EDF file. See tracker file
% DATA.INI for types.
% Arguments: <list>: list of event types
% LEFT, RIGHT events for one or both eyes
% FIXATION fixation start and end events
% FIXUPDATE fixation (pursuit) state updates
% SACCADE saccade start and end
% BLINK blink start an end
% MESSAGE messages (user notes in file)
% BUTTON button 1..8 press or release
% INPUT changes in input port lines
eyelink('command', 'link_event_filter = LEFT,RIGHT,FIXATION');
% Sets which types of events will be sent through link. See tracker file
% DATA.INI for types.
% Arguments: <list>: list of event types
% LEFT, RIGHT events for one or both eyes
% FIXATION fixation start and end events
% FIXUPDATE fixation (pursuit) state updates
% SACCADE saccade start and end
% BLINK blink start an end
% MESSAGE messages (user notes in file)
% BUTTON button 1..8 press or release

eyelink('command', 'link_sample_data  = LEFT,RIGHT,GAZE,AREA');
% Sets data in samples sent through link. See tracker file DATA.INI for
% types.
% Arguments: <list>: list of data types
% GAZE screen xy (gaze) position
% GAZERES units-per-degree screen resolution
% HREF head-referenced gaze
% PUPIL raw eye camera pupil coordinates
% AREA pupil area
% STATUS warning and error flags
% BUTTON button state and change flags
% INPUT input port data lines

% %file_name=input('Input file name:','s');
% file_name=['bcc.' datestr(now,29) '_00' ]
% edf_name=file_name([1:3 15:end] );
% i = EYELINK('openfile',[edf_name,'.edf']);
% if i~=0 & button(1)~='D'
% 	EYELINK('Shutdown');
% 	disp(' ');
% 	error(['Cannot create EDF file: ' file_name]);
%     return;
% end



clc;
Screen('Preference', 'VisualDebuglevel', 3); % 4 is default but it makes a painful white screen
if nargin ==0
    [w,screenRect] = SCREEN('OpenWindow',1);
end
el=EyelinkInitDefaults(w);
el.backgroundcolour=[0 0 0];
ListenChar(2)
err=EyelinkDoTrackerSetup(el,'d');
ListenChar(0)
if nargin ==0
    SCREEN('closeall');
end
%status = Eyelink('ReceiveFile',edf_name, [file_name '.edf']);
%EYELINK('Shutdown');

return


